import { Body, Controller, Delete, Get, Param, Post } from '@nestjs/common';
import { RolesService } from './roles.service';
import { ApiOperation, ApiTags } from '@nestjs/swagger';
import { RolesDto } from '../dto/roles.dto';
import { CreateAssignAuthToRole } from 'src/dto/user.dto';

@ApiTags('角色')
@Controller('roles')
export class RolesController {
  constructor(private readonly service: RolesService) {}

  @Post('addRole')
  @ApiOperation({ summary: '添加角色' })
  async addRole(@Body() rolesDto: RolesDto) {
    return this.service.addRole(rolesDto);
  }

  @Get('queryRoles')
  @ApiOperation({ summary: '获取所有角色' })
  async queryRoles() {
    return await this.service.queryRoles();
  }

  @Get('getRoleById/:id')
  @ApiOperation({ summary: '获取角色信息' })
  async getRoleById(@Param('id') id: string) {
    return this.service.getRoleById(id);
  }

  @Delete('deleteUserById/:id')
  @ApiOperation({ summary: '删除角色' })
  async deleteUserById(@Param('id') id: string) {
    return this.service.deleteUserById(id);
  }

  @Post('assignAuthToRole')
  @ApiOperation({ summary: '角色添加单个或多个权限' })
  async assignAuthToRole(@Body() dto: CreateAssignAuthToRole) {
    return this.service.assignAuthToRole(dto.roleId, dto.authIds);
  }
}
